package com.matrix.java.chap_04;

import java.util.Scanner;

/*
    检查 SSN
 */
public class Ex4_21 {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        System.out.print("Enter a SSN: ");
        String str = input.next();
        String numbers = "0123456789";
        if (str.length() == 11
                && str.charAt(3) == '-'
                && str.charAt(6) == '-'
                && numbers.contains(str.substring(0, 1))
                && numbers.contains(str.substring(1, 2))
                && numbers.contains(str.substring(2, 3))
                && numbers.contains(str.substring(4, 5))
                && numbers.contains(str.substring(5, 6))
                && numbers.contains(str.substring(7, 8))
                && numbers.contains(str.substring(8, 9))
                && numbers.contains(str.substring(9, 10))
                && numbers.contains(str.substring(10))) {
            System.out.println(str + " is a valid social security number");
        } else {
            System.out.println(str + " is an invalid social security number");
        }
        input.close();
    }
}
